package com.hu.hutool.ThreadUtil;

import cn.hutool.core.thread.ThreadUtil;
import com.commons.tools.utils.SpringContextUtil;
import com.hu.hutool.dao.UserDao;
import com.hu.hutool.dto.vo.UserVo;
import com.hu.hutool.entity.User;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

/**
 * @Author CazCen
 * @Date 2021/11/16 12:58
 */
@Slf4j
public class CallableB1 implements Callable {

    // 多线程无法直接注入bean的，需要通过上下文获取

    private UserDao userDAO = (UserDao) SpringContextUtil.getBean("userDao");


    @Override
    public User call() throws Exception {
        UserVo vo = new UserVo();
        vo.setId(1);
        User oneUser = userDAO.getOneUser(vo);
        log.info("当前线程开始执行B1了  threadName:{}", Thread.currentThread().getName());
        ThreadUtil.sleep(2, TimeUnit.SECONDS);
        log.info("当前线程执行完B1了  threadName:{}", Thread.currentThread().getName());
        return oneUser;
    }
}
